package com.my.hotel.service.impl;

import com.my.hotel.entity.KfImg;
import com.my.hotel.entity.KfRoom;
import com.my.hotel.entity.KfType;
import com.my.hotel.mapper.KfImgMapper;
import com.my.hotel.mapper.KfRoomMapper;
import com.my.hotel.mapper.KfTypeMapper;
import com.my.hotel.service.KfRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class KfRoomServiceImpl implements KfRoomService {

    @Autowired
    private KfRoomMapper kfRoomMapper;
    @Autowired
    private KfImgMapper kfImgMapper;

    @Autowired
    private KfTypeMapper kfTypeMapper;

    public List<KfRoom> getList() {
        List<KfRoom> list = kfRoomMapper.getList();
        for (KfRoom kfRoom : list) {
            int kfTypeId = kfRoom.getKfTypeId();
            KfType kfType = kfTypeMapper.getKfTypeById(kfTypeId);
            kfRoom.setKfType(kfType);
        }
        return list;
    }

    public List<KfRoom> getListBykfTypeId(String kfTypeId) {
        return kfRoomMapper.getListBykfTypeId(kfTypeId);
    }

    @Transactional
    public void addKfRoom(KfRoom kfRoom,String fileImg) {
        kfRoomMapper.addKfRoom(kfRoom);
        int kfId = kfRoom.getId();
        KfImg kfImg = new KfImg();
        kfImg.setKfId(kfId);
        kfImg.setKfImgPath(fileImg);
        kfImgMapper.addKfImg(kfImg);
    }

    public KfRoom getKfRoomById(int id) {
        return kfRoomMapper.getKfRoomById(id);
    }

    public void updateKfRoom(KfRoom kfRoom) {
        kfRoomMapper.updateKfRoom(kfRoom);
    }

    public void deleteKfRoom(int id) {
        kfRoomMapper.deleteKfRoom(id);
    }

    public List<Map> getAvg() {
        return kfRoomMapper.getAvg();
    }
}
